package part19_状态模式_抽奖;

import java.util.Random;

/**可以抽奖状态
 * @ClassName: CanRaffleState
 * @Author: AllenSun
 * @Date: 2020/3/9 21:11
 */
public class CanRaffleState extends State {

    RaffleActivity activity;

    public CanRaffleState(RaffleActivity activity) {
        this.activity = activity;
    }

    //已经扣除了积分，不能再扣
    @Override
    public void deductMoney() {
        System.out.println("已经扣取过了积分");
    }

    //可以抽象，抽完奖后，根据实际情况，改成新的状态
    @Override
    public boolean raffle() {
        System.out.println("正在抽奖，请稍等！");
        Random random=new Random();
        int num=random.nextInt(10);
        if(num==0){
            System.out.println("恭喜中奖");
            activity.setState(activity.getDispenseState());
            return true;
        }else {
            System.out.println("很遗憾没有抽中奖品");
            activity.setState(activity.getNoRaffleState());
            return false;
        }
    }

    //不能发放奖品
    @Override
    public void despendePrize() {
        System.out.println("没中奖，不能发放奖品");
    }
}
